using Microsoft.Extensions.Configuration;
using SqlSugar;

namespace LabSecurityApi.Config;

public static class SqlSugarConfig
{
    public static void AddSqlSugarSetup(this IServiceCollection services, IConfiguration configuration)
    {
        SqlSugarScope sqlSugar = new SqlSugarScope(new ConnectionConfig()
        {
            DbType = DbType.SqlServer,
            ConnectionString = configuration.GetConnectionString("DefaultConnection"),
            IsAutoCloseConnection = true,
            InitKeyType = InitKeyType.Attribute,
        },
        db =>
        {
            // 打印SQL语句
            db.Aop.OnLogExecuting = (sql, pars) =>
            {
                Console.WriteLine(sql);
            };
        });

        services.AddSingleton<ISqlSugarClient>(sqlSugar);
    }
} 